using UnityEngine;
using UnityEngine.UIElements;

namespace MinesweeperPlus.Scripts.Utils
{
    public static class Extensions
    {
        public static bool GetDisplay(this VisualElement visualElement)
        {
            return visualElement.style.display == DisplayStyle.Flex;
        }
        public static VisualElement SetDisplay(this VisualElement visualElement, bool value)
        {
            visualElement.style.display = value ? DisplayStyle.Flex : DisplayStyle.None;
            return visualElement;
        }

        public static VisualElement SetTextColor(this VisualElement visualElement, Color color)
        {
            visualElement.style.color = color;
            return visualElement;
        }

        public static VisualElement SetBackgroundColor(
            this VisualElement visualElement, 
            Color color)
        {
            visualElement.style.backgroundColor = color;
            return visualElement;
        }
        public static VisualElement SetBackgroundImage(
            this VisualElement visualElement, 
            VectorImage vectorImage)
        {
            visualElement.style.backgroundImage = Background.FromVectorImage(vectorImage);
            return visualElement;
        }
        public static VisualElement SetBackgroundImageColor(
            this VisualElement visualElement,
            Color color)
        {
            visualElement.style.unityBackgroundImageTintColor = color;
            return visualElement;
        }
        
        public static VisualElement SetBorderColor(this VisualElement visualElement, Color color)
        {
            visualElement.style.borderTopColor = color;
            visualElement.style.borderBottomColor = color;
            visualElement.style.borderLeftColor = color;
            visualElement.style.borderRightColor = color;
            return visualElement;
        }
    
        public static VisualElement Rotate(this VisualElement visualElement, float angle)
        {
            visualElement.transform.rotation *= Quaternion.Euler(0f, 0f, angle);
            return visualElement;
        }
    }
}
